//
//  StatusTopView.m
//  weibo110
//
//  Created by 臧松 on 15/12/31.
//  Copyright © 2015年 臧松. All rights reserved.
//
#define StatusCellMargin 12
#define StatusCellIconWidth @35

#import "StatusTopView.h"
#import "UILabel+Extension.h"
#import "Masonry.h"
#import "UIImageView+WebCache.h"
@interface StatusTopView()
// 头像
@property (nonatomic,strong) UIImageView * iconView;

// 姓名
@property (nonatomic,strong) UILabel * nameLabel;

// 会员图标
@property (nonatomic,strong) UIImageView * numberIconView;

// 认证图标
@property (nonatomic,strong) UIImageView * vipIconView;

// 时间标签
@property (nonatomic,strong) UILabel * timeLabel;

// 来源标签
@property (nonatomic,strong) UILabel * sourceLabel;

@end

@implementation StatusTopView
// 微博视图模型
-(void)setStatusViewModel:(StatusViewModel *)statusViewModel{
    _statusViewModel = statusViewModel;
    // 设置姓名
    self.nameLabel.text = statusViewModel.status.user.screen_name;
    
    // 设置头像
    [self.iconView sd_setImageWithURL:statusViewModel.userProfileUrl placeholderImage:statusViewModel.userDefaultIconView];
    
    // 设置会员图标
    self.numberIconView.image = statusViewModel.userNumberImage;
    
    // 设置认证图标
    self.vipIconView.image = statusViewModel.userVipImage;
    
#warning
    // 设置来源
    self.sourceLabel.text = @"黑马微博";
    
    // 设置时间
    self.timeLabel.text = @"刚刚";
}
-(UIImageView *)iconView{
    if (_iconView == nil) {
        _iconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"avatar_default_big"]];
    }
    return _iconView;
}
-(UILabel *)nameLabel{
    if (_nameLabel == nil) {
        _nameLabel = [UILabel labelWithTitle:@"王老五" fontSize:14 color:[UIColor darkGrayColor] screenInset:0];
       
    }
    return _nameLabel;
}

-(UIImageView *)numberIconView{
    
    if (_numberIconView == nil) {
        _numberIconView = [[UIImageView  alloc]initWithImage:[UIImage imageNamed:@"common_icon_membership_level1"]];
    }
    return _numberIconView;
}

-(UIImageView *)vipIconView{
    if (_vipIconView == nil) {
        _vipIconView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"avatar_vip"]];
    }
    return _vipIconView;
}
-(UILabel *)timeLabel{
    if (_timeLabel == nil) {
        _timeLabel = [UILabel labelWithTitle:@"刚刚" fontSize:12 color:[UIColor orangeColor] screenInset:0];
        
    }
    return _timeLabel;
}
-(UILabel *)sourceLabel{
    if (_sourceLabel == nil) {
        _sourceLabel = [UILabel labelWithTitle:@"黑马微博" fontSize:12 color:[UIColor darkGrayColor] screenInset:0];
        
    }
    return _sourceLabel;
}
-(instancetype)init{
    
    if (self = [super init]) {
        
        [self setupUI];
    }
    return self;
}

// MARK: - 设置界面
-(void)setupUI{
    
    self.backgroundColor = [UIColor colorWithWhite:0.95 alpha:1.0];
    // 1. 添加控件
    UIView * sepView = [[UIView alloc]init];
    sepView.backgroundColor = [UIColor lightGrayColor];
    
    [self addSubview:sepView];
    
    [self addSubview:self.iconView];
    [self addSubview:self.nameLabel];
    [self addSubview:self.numberIconView];
    [self addSubview:self.vipIconView];
    [self addSubview:self.timeLabel];
    [self addSubview:self.sourceLabel];
    
    // 2. 设置布局
    [sepView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left);
        make.right.equalTo(self.mas_right);
        make.top.equalTo(self.mas_top);
        make.height.equalTo(@StatusCellMargin);
    }];
    // 头像
    [self.iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(StatusCellMargin);
        make.top.equalTo(sepView.mas_bottom).offset(StatusCellMargin);
        make.height.equalTo(StatusCellIconWidth);
        make.width.equalTo(StatusCellIconWidth);
    }];
    // 姓名
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView.mas_top);
        make.left.equalTo(self.iconView.mas_right).offset(StatusCellMargin);
    }];
    //会员
    [self.numberIconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.iconView.mas_top);
        make.left.equalTo(self.nameLabel.mas_right).offset(StatusCellMargin);
    }];
    // 认证
    [self.vipIconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.iconView.mas_right);
        make.centerY.equalTo(self.iconView.mas_bottom);
    }];
    // 时间
    [self.timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel.mas_left);
        make.bottom.equalTo(self.iconView.mas_bottom);
    }];
    // 来源
    [self.sourceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.timeLabel.mas_right).offset(StatusCellMargin);
        make.bottom.equalTo(self.iconView.mas_bottom);
    }];
    
    
}
@end
